import router from '@/router';
import axios from 'axios'
import qs from 'qs';
export default class RestUtil{
    //当前前端环境域名
    public static basicUrl="http://localhost:8087";
    //get请求，第一个参数为url,第二个为传递参数
    public static async get(url:string,params:any){
         const result:any=await axios.get(RestUtil.basicUrl+url,params);
         return result;
    }
    public static async post(url:string,params:any){
        const result=await axios.post(RestUtil.basicUrl+url,qs.stringify(params), {headers: {'Content-Type':'application/x-www-form-urlencoded'}});
        return result;
   }
}
// request拦截器
axios.interceptors.request.use((config:any) => {
        config.headers['token'] = "";
        return config
}, error => {
      console.log("请求拦截错误消息:",error);
});
//响应拦截
axios.interceptors.response.use((response:any) => {
      if(response.status!==200){
          router.push({path:"/login"});
      }
      return response;
},error => {
       console.log("响应拦截错误消息:",error);
});